﻿using System;
using System.Collections.Generic;
using Jayden.Dll.Web.HtmlControls.Descriptions;
using Jayden.Dll.Web.HtmlControls.Generics;

namespace Jayden.Dll.Web.HtmlControls
{
	public class Li : HtmlElement
	{
		public Li() : base(LiDescription.Instance) { }
		public Li(string text, bool htmlEncode = true)
			: this()
		{
			if (text != null)
				AddText(text, htmlEncode);
		}
		public Li(string text, string href, bool htmlEncode = true)
			: this()
		{
			if (text != null)
			{
				if (href == null)
					AddText(text, htmlEncode);
				else
				{
					A a = AddControl<A>();
					a.AddText(text, htmlEncode);
					a["href"] = href;
				}
			}
		}

		public uint? Value { get { return GetAttributeUint("value"); } set { SetAttribute("value", value); } }
	}
	public class LiDescription : HtmlElementDescription
	{
		public static readonly LiDescription Instance = new LiDescription();
		private LiDescription() : base("li") { }
		public override Type ControlType { get { return typeof(Li); } }
		public override bool OnlyFlowContent { get { return true; } }
		public override string Description { get { return "list item."; } }
		public override IEnumerable<HtmlElementDescription> PermittedElements { get { yield break; } }

		public override IEnumerable<HtmlElementDescription> PermittedParents
		{
			get
			{
				yield return UlDescription.Instance;
				yield return OlDescription.Instance;
				yield return MenuDescription.Instance;
			}
		}

		public override IEnumerable<string> PermittedAttributes { get { yield return "value"; } }
	}
}
